package org.cbg.until;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;

import com.tool.tcpimg.UIUtils;
import org.cbg.btn.TrslationBtn;
import org.cbg.entity.Salegoods;
import org.cbg.panel.TraslationWantBuyDahuabiModelJpanel;
import org.come.until.CutButtonImage;
import org.come.until.cbgSrcollPanelUI;



public class TraslationTableDahuabiUntil extends JPanel {

    TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel;

    public TraslationTableDahuabiUntil() {
        // TODO Auto-generated constructor stub
    }

    /**
     * 自行生成结果展示
     * 
     * @param jScrollPane
     * @param geshu
     *            多少条数据
     */
    public static void TableModel(JScrollPane jScrollPane, int geshu) {
        /**
         * 表格
         */
        JPanel jPanel = new JPanel();
        jPanel.setBackground(null);
        jPanel.setOpaque(false);
        jPanel.setBorder(null);
        jPanel.setLayout(null);
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(jPanel);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                StringBuilder sb = new StringBuilder();
                sb.append("当前进入的按钮是：\n").append(btn.getName()).append("\n").append("正在进行演示自定义Tooltip！\n")
                        .append("请自行查看源码");
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < geshu; i++) {
            TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel();
            traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
            traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个面板");
            MListener m = new MListener();
            traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
            // traslationWantBuyDahuabiModelJpanel.addMouseListener(new
            // MouseListener() {
            //
            // @Override
            // public void mouseReleased(MouseEvent e) {
            // // TODO Auto-generated method stub
            //
            // }
            //
            // @Override
            // public void mousePressed(MouseEvent e) {
            // // TODO Auto-generated method stub
            //
            // }
            //
            // @Override
            // public void mouseExited(MouseEvent e) {
            // // TODO Auto-generated method stub
            // traslationWantBuyDahuabiModelJpanel.setBackground(null);
            // traslationWantBuyDahuabiModelJpanel.setOpaque(false);
            // }
            //
            // @Override
            // public void mouseEntered(MouseEvent e) {
            // // TODO Auto-generated method stub
            // traslationWantBuyDahuabiModelJpanel.setBackground(UIUtils.COLOR_cbg5);
            // traslationWantBuyDahuabiModelJpanel.setOpaque(true);
            // }
            //
            // @Override
            // public void mouseClicked(MouseEvent e) {
            // // TODO Auto-generated method stub
            // }
            // });

            jPanel.add(traslationWantBuyDahuabiModelJpanel);
        }
        jPanel.setPreferredSize(new Dimension(760, 62 * geshu));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 根据查询条件查询结果展示
     * 
     * @param jScrollPane
     * @param salegoodsList
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Salegoods> salegoodsList) {
        /**
         * 表格
         */
        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                StringBuilder sb = new StringBuilder();
                sb.append("当前进入的按钮是：\n").append(btn.getName()).append("\n").append("正在进行演示自定义Tooltip！\n")
                        .append("请自行查看源码");
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < salegoodsList.size(); i++) {
            TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel(
                    salegoodsList.get(i));
            traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
            traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个新" + i + "面板");
            MListener m = new MListener();
            traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
            // jPanel.add(traslationWantBuyDahuabiModelJpanel);
            view.add(traslationWantBuyDahuabiModelJpanel);
        }

        // jPanel.setPreferredSize(new Dimension(760, 62 *
        // salegoodsList.size()));
        view.setPreferredSize(new Dimension(760, 62 * salegoodsList.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 根据查询条件查询结果展示
     * 
     * @param jScrollPane
     * @param salegoodsList
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Salegoods> salegoodsList,
            List<BigDecimal> bigDecimalsList) {
        /**
         * 表格
         */


        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
            }
        }
        for (int i = 0; i < salegoodsList.size(); i++) {
            TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel(
                    salegoodsList.get(i));
            traslationWantBuyDahuabiModelJpanel.setBounds(0, i * 62, 740, 60);
            traslationWantBuyDahuabiModelJpanel.setName("第" + i + "个新" + i + "面板");
            MListener m = new MListener();
            traslationWantBuyDahuabiModelJpanel.addMouseListener(m);
            // jPanel.add(traslationWantBuyDahuabiModelJpanel);
            view.add(traslationWantBuyDahuabiModelJpanel);

            /**
             * 判断是否收藏
             */
            if (bigDecimalsList.contains(salegoodsList.get(i).getSaleid())) {
                TrslationBtn component2 = (TrslationBtn) traslationWantBuyDahuabiModelJpanel.getComponent(2);
                try {
                    component2.setIcons(CutButtonImage.cuts("inkImg/number/b4/scxx.png"));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                traslationWantBuyDahuabiModelJpanel.setStateOrNo(0);
            }
        }

        // jPanel.setPreferredSize(new Dimension(760, 62 *
        // salegoodsList.size()));
        view.setPreferredSize(new Dimension(760, 62 * salegoodsList.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

}
